package client.gui;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;

import javax.swing.JPanel;

import client.logic.Facade;
import encription.SecurityHandler;

/**
 * a panel that shows all the actions which users can do
 * the panel has 4 buttons - display the online users , show all of the users,
 * logout from the system , delete yourself from the system
 */
public class pnlMainScreen extends JPanel {
	/**
	 *
	 */
	private static final long serialVersionUID = 1L;
	private JButton btnWhosOnline;
	private JLabel lblHeadline;
	private JButton btnLogoff;
	private JButton btnDelete;
	private JButton btnAlluser;

	public pnlMainScreen(){
		initGUI();
	}

	private void initGUI() {
		try {
			{
				this.setPreferredSize(new java.awt.Dimension(354, 223));
				this.setLayout(null);
				{
					btnWhosOnline = new JButton();
					this.add(btnWhosOnline);
					btnWhosOnline.setText("See who is online");
					btnWhosOnline.setBounds(95, 103, 173, 20);
					btnWhosOnline.addActionListener(new ActionListener(){
						public void actionPerformed(ActionEvent e){
							Facade.getInstance().askForOnline();
						}
					});
				}
				{
					lblHeadline = new JLabel();
					this.add(lblHeadline);
					lblHeadline.setText("User Panel");
					lblHeadline.setBounds(62, 23, 98, 16);
				}
				{
					btnAlluser = new JButton();
					this.add(btnAlluser);
					btnAlluser.setText("List all users");
					btnAlluser.setBounds(95, 72, 173, 20);
					btnAlluser.addActionListener(new ActionListener(){
						public void actionPerformed(ActionEvent e){
							Facade.getInstance().askForAllUsers();
						}
					});
				}
				{
					btnLogoff = new JButton();
					this.add(btnLogoff);
					btnLogoff.setText("Log out");
					btnLogoff.setBounds(95, 165, 173, 20);
					btnLogoff.addActionListener(new ActionListener(){
						public void actionPerformed(ActionEvent e){
							Facade.getInstance().logout();
						}
					});
				}
				{
					btnDelete = new JButton();
					this.add(btnDelete);
					btnDelete.setText("Delete me");
					btnDelete.setBounds(95, 134, 173, 20);
					btnDelete.addActionListener(new ActionListener(){
						public void actionPerformed(ActionEvent e){
							Facade.getInstance().delete();
						}
					});
				}
			}
		} catch(Exception e) {
			SecurityHandler.catchException("initializing the main user panel", e, false);
			//e.printStackTrace();
		}
	}

}
